
#include <pthread.h>

#include "ThreadData.h"

namespace Veda{

VThreadData::VThreadData()
{
	m_internal = new VThreadDataInternal;
	m_internal->m_key = 0;
	m_internal->m_isValid = (pthread_key_create(&m_internal->m_key, NULL) == 0);
}

VThreadData::~VThreadData()
{
	if(m_internal->m_isValid)
	{
		pthread_key_delete(m_internal->m_key);
	}
	delete m_internal;
}

bool VThreadData::isValid()
{
	return m_internal->m_isValid;
}

bool VThreadData::setData(const void* pdata)
{
	if(m_internal->m_isValid)
	{
		return (pthread_setspecific(m_internal->m_key, pdata) == 0);
	}
	else
	{
		return false;
	}
}

void* VThreadData::getData()
{
	if(m_internal->m_isValid)
	{
		return pthread_getspecific(m_internal->m_key);
	}
	else
	{
		return NULL;
	}
}

}

